package com.controleur.listener.impl;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JButton;

import com.main.EasyLunch;
import com.modele.dao.impl.RestaurantDAO;
import com.modele.entity.Restaurant;
import com.vue.Fenetre;
import com.vue.RestaurantListeVue;

public class RestaurantListeListener implements ActionListener{
	
	public Fenetre fenetre;
	public Restaurant resto;
	
	public RestaurantListeListener(Fenetre f){
		this.fenetre=f;
	}


	@Override
	public void actionPerformed(ActionEvent e) {
		RestaurantDAO dao = (RestaurantDAO)EasyLunch.getFactory().getRestaurantDAO();
		List<Restaurant> list = null;
		String type = null ;
		if ( ((JButton)e.getSource()).getText().equals("Rechercher") ){
			RestaurantListeVue form = (RestaurantListeVue)fenetre.getPanneauApplication();
			type = form.getType().getSelectedItem().toString();
			if(type.equals("tout")){
				list = dao.findAll();
			}else{
				list = dao.findByType(type);
			}
		}
		
		
		
		fenetre.setPanneau(new RestaurantListeVue(fenetre,list,type));
	}
}
